package com.panda.utils;

import com.panda.pojo.Context;
import com.panda.pojo.Element;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

class InsertUtils {

    //这里不能引用IdUtils中的name
    private static Pattern pattern = Pattern.compile(">>>[\n ]*((__js_string_[a-zA-Z][a-zA-Z0-9]*_[0-9]+)|((\\$scope\\.[ \n]*)?[a-zA-Z_][a-zA-Z_0-9]*([ \n]*\\.[ \n]*[a-zA-Z_][a-zA-Z_0-9]*)*))");

    static String transform(Context context, Element element, String s) {

        if ("".equals(s)) {
            return s;
        }

        Matcher matcher = pattern.matcher(s);

        String t = s;

        while (matcher.find()) {

            t = t.replace(matcher.group(), ".appendTo(" + matcher.group(1) + ")");

        }

        return t;
    }


}

